"""
@Project ：HaloInterfaceProject 
@File    ：CreateUser.py
@IDE     ：PyCharm 
@Author  ：张成龙
@Date    ：2024/10/24 17:06 
@explain ：新增用户
"""
import requests

from api import SYSTEM_URL, SESSION
from utils.FakerDataUtil import FakerDataUtil


class CreateUser:

    def __init__(self):
        self.url = SYSTEM_URL + "/apis/api.console.halo.run/v1alpha1/users"
        self.headers = {
            'Cookie': SESSION
        }
        self.name = FakerDataUtil.faker_user_name()
        self.password = FakerDataUtil.faker_password()
        self.email = FakerDataUtil.faker_email()
        self.description = FakerDataUtil.faker_random_text()

    def create_user(self, roles):

        body = {
            "avatar": "",
            "bio": self.description,
            "displayName": self.name,
            "email": self.email,
            "name": self.name,
            "password": self.password,
            "roles": [
                roles
            ]
        }

        response = requests.post(self.url, headers=self.headers, json=body)
        return response
